/*
  说明：
  {
    path: '/documentation',  （路径）
    component: Layout,  （不变）
    redirect: '/documentation/index',  （重定向到该路由）
    children: [{
      path: 'index', （子路由路径）
      component: _import('documentation/index'),  （引入vue组件，此处指views/documentation/index.vue）
      name: 'documentation',  （组件名）
      meta: { title: '文档',（该title决定了侧栏显示的文字 如：文档） icon: 'documentation', noCache: true }
    }]
  }
*/
import Vue from 'vue'
import Router from 'vue-router'
const _import = require('./_import_' + process.env.NODE_ENV)
// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading
Vue.use(Router)
// Layout 组件为功能操作区域 所有操作区组件都是它的子路由
import Layout from '../views/layout/Layout'
// 默认路由 start
export const constantRouterMap = [
    /* 登录 */
    {
        path: '/login',
        component: _import('login/index'),
        hidden: true
    },
    {
        path: '/authredirect',
        component: _import('login/authredirect'),
        hidden: true
    },
    {
        path: '/404',
        component: _import('errorPage/404'),
        hidden: true
    },
    {
        path: '/401',
        component: _import('errorPage/401'),
        hidden: true
    },
    /* 主面板（首页） */
    {
        path: '',
        component: Layout,
        redirect: 'dashboard',
        children: [{
            path: 'dashboard',
            component: _import('dashboard/index'),
            name: 'dashboard',
            meta: {
                title: '首页',
                icon: 'dashboard',
                noCache: true
            }
        }]
    },
]
// 默认路由 end
export default new Router({
    mode: 'hash',
    scrollBehavior: () => ({
        y: 0
    }),
    routes: constantRouterMap
})
// 异步路由 具体根据权限在permission.js做判断    在这里加路由
export const asyncRouterMap = [		
    /* ------------------------功能-------------------------- */
    {
        path: '/functions',
        component: Layout,
        redirect: 'noredirect',
        name: 'functions',
        meta: {
            title: '功能',
            icon: 'component'
        },
        children: [
            //营销管理
            {
                path: 'market',
                component: _import('functions/market'),
                name: 'market',
                meta: {
                    title: '营销管理',
                    noCache: true
                }
            },
            //优惠券管理
            {
                path: 'coupon',
                component: _import('functions/coupon'),
                name: 'coupon',
                meta: {
                    title: '优惠券管理',
                    noCache: true
                }
            },
            //广告位管理
            {
                path: 'advertisement',                
                component: _import('functions/advertisement'),
                name: 'advertisement',
                meta: {
                    title: '广告位管理',
                    noCache: true
                }
            },
            //积分商城管理
            {
                path: 'integral',
                component: _import('functions/integral'),
                name: 'integral',
                meta: {
                    title: '积分商城管理',
                    noCache: true
                }
            }
        ]
    },
    //新增营销
    {
        path: '/functions',
        component: Layout,
        hidden: true,
        children: [{
            path: 'addMarket',
            component: _import('functions/addMarket'),
            name: 'addMarket',
            meta: {
                title: '新增营销',
                icon: 'icon',
                noCache: true
            }
        }]
    },
    //编辑营销
    {
        path: '/functions',
        component: Layout,
        hidden: true,
        children: [{
            path: 'editMarket/:id',
            component: _import('functions/editMarket'),
            name: 'editMarket',
            meta: {
                title: '编辑营销',
                icon: 'icon',
                noCache: true
            }
        }]
    },
    //新增优惠券
    {
        path: '/functions',
        component: Layout,
        hidden: true,
        children: [{
            path: 'addCoupon',
            component: _import('functions/addCoupon'),
            name: 'addCoupon',
            meta: {
                title: '新增优惠券',
                icon: 'icon',
                noCache: true
            }
        }]
    },
    //积分商城的 新增优惠券
    {
        path: '/functions',
        component: Layout,
        hidden: true,
        children: [{
            path: 'addIntegral',
            component: _import('functions/addIntegral'),
            name: 'addIntegral',
            meta: {
                title: '新增优惠券',
                icon: 'icon',
                noCache: true
            }
        }]
    },
    //分发优惠券
    {
        path: '/functions',
        component: Layout,
        hidden: true,
        children: [{
            path: 'sendCoupon',
            component: _import('functions/sendCoupon'),
            name: 'sendCoupon',
            meta: {
                title: '分发优惠券',
                icon: 'icon',
                noCache: true
            }
        }]
    },
    //分发记录
    {
        path: '/functions',
        component: Layout,
        hidden: true,
        children: [{
            path: 'sendRecord',
            component: _import('functions/sendRecord'),
            name: 'sendRecord',
            meta: {
                title: '分发记录',
                icon: 'icon',
                noCache: true
            }
        }]
    },
    //增加广告位
    {
        path: '/functions',
        component: Layout,
        hidden: true,
        children: [{
            path: 'addAd',
            component: _import('functions/addAd'),
            name: 'addAd',
            meta: {
                title: '增加广告位',
                icon: 'icon',
                noCache: true
            }
        }]
    },
    //编辑广告位
    {
        path: '/functions',
        component: Layout,
        hidden: true,
        children: [{
            path: 'editAd/:id',
            component: _import('functions/editAd'),
            name: 'editAd',
            meta: {
                title: '编辑广告位',
                icon: 'icon',
                noCache: true
            }
        }]
    },
    //编辑优惠券
    {
        path: '/functions',
        component: Layout,
        hidden: true,
        children: [{
            path: 'editCoupon/:id',
            component: _import('functions/editCoupon'),
            name: 'editCoupon',
            meta: {
                title: '编辑优惠券',
                icon: 'icon',
                noCache: true
            }
        }]
    },
    //积分商城 编辑优惠券
    {
        path: '/functions',
        component: Layout,
        hidden: true,
        children: [{
            path: 'editIntegral/:id',
            component: _import('functions/editIntegral'),
            name: 'editIntegral',
            meta: {
                title: '编辑优惠券',
                icon: 'icon',
                noCache: true
            }
        }]
    },
    /* --------------------管理----------------------- */
    {
        path: '/manages',
        component: Layout,
        redirect: 'noredirect',
        name: 'manages',
        meta: {
            title: '管理',
            icon: 'documentation'
        },
        children: [
            //门店管理
            {
                path: 'store',
                component: _import('manages/store'),
                name: 'store',
                meta: {
                    title: '门店管理',
                    noCache: true
                }
            },
            //商品管理
            {
                path: 'goods',
                component: _import('manages/goods'),
                name: 'goods',
                meta: {
                    title: '商品管理',
                    noCache: true
                }
            },
            //会员管理
            {
                path: 'member',
                component: _import('manages/member'),
                name: 'member',
                meta: {
                    title: '会员管理',
                    noCache: true
                }
            },
            //订单管理
            {
                path: 'order',
                component: _import('manages/order'),
                name: 'order',
                meta: {
                    title: '订单管理',
                    noCache: true
                }
            },
            //退款管理
            {
                path: 'refund',
                component: _import('manages/refund'),
                name: 'refund',
                meta: {
                    title: '退款管理',
                    noCache: true
                }
            }
        ]
    },
    //新增门店
    {
        path: '/manages',
        component: Layout,
        hidden: true,
        children: [{
            path: 'addStore',
            component: _import('manages/addStore'),
            name: 'addStore',
            meta: {
                title: '新增门店',
                icon: 'icon',
                noCache: true
            }
        }]
    },
    //新增商品
    {
        path: '/manages',
        component: Layout,
        hidden: true,
        children: [{
            path: 'addGoods',
            component: _import('manages/addGoods'),
            name: 'addGoods',
            meta: {
                title: '新增商品',
                icon: 'icon',
                noCache: true
            }
        }]
    },
    //商品分类
    {
        path: '/manages',
        component: Layout,
        hidden: true,
        children: [{
            path: 'goodsClassify',
            component: _import('manages/goodsClassify'),
            name: 'goodsClassify',
            meta: {
                title: '商品分类',
                icon: 'icon',
                noCache: true
            }
        }]
    },
    //编辑商品分类
    {
        path: '/manages',
        component: Layout,
        hidden: true,
        children: [{
            path: 'editGoods',
            component: _import('manages/editGoods'),
            name: 'editGoods',
            meta: {
                title: '编辑商品分类',
                icon: 'icon',
                noCache: true
            }
        }]
    },
    //会员详情
    {
        path: '/manages',
        component: Layout,
        hidden: true,
        children: [{
            path: 'memberDetail/:id',
            component: _import('manages/memberDetail'),
            name: 'memberDetail',
            meta: {
                title: '会员详情',
                icon: 'icon',
                noCache: true
            }
        }]
    },
    //订单详情
    {
        path: '/manages',
        component: Layout,
        hidden: true,
        children: [{
            path: 'orderDetail/:id',
            component: _import('manages/orderDetail'),
            name: 'orderDetail',
            meta: {
                title: '订单详情',
                icon: 'icon',
                noCache: true
            }
        }]
    },
    {
        //退款详情
        path: '/manages',
        component: Layout,
        hidden: true,
        children: [{
            path: 'refundDetail/:id',
            component: _import('manages/refundDetail'),
            name: 'refundDetail',
            meta: {
                title: '退款详情',
                icon: 'icon',
                noCache: true
            }
        }]
    },
    /* --------------------统计----------------------- */
    {
        path: '/statistics',
        component: Layout,
        redirect: 'noredirect',
        name: 'statistics',
        meta: {
            title: '统计',
            icon: 'icon'
        },
        children: [
            //用户分析
            {
                path: 'userAnalysis',
                component: _import('statistics/userAnalysis'),
                name: 'userAnalysis',
                meta: {
                    title: '用户分析',
                    noCache: true
                }
            },
            //订单分析
            {
                path: 'orderAnalysis',
                component: _import('statistics/orderAnalysis'),
                name: 'orderAnalysis',
                meta: {
                    title: '订单分析',
                    noCache: true
                }
            },
            //储存卡分析
            {
                path: 'cardAnalysis',
                component: _import('statistics/cardAnalysis'),
                name: 'cardAnalysis',
                meta: {
                    title: '储存卡分析',
                    noCache: true
                }
            },
        ]
    },
    /* --------------------设置----------------------- */
    {
        path: '/setting',
        component: Layout,
        redirect: 'noredirect',
        name: 'setting',
        meta: {
            title: '设置',
            icon: 'setting'
        },
        children: [
            // 积分设置
            {
                path: 'integralSet',
                component: _import('setting/integralSet'),
                name: 'integralSet',
                meta: {
                    title: '积分设置',
                    noCache: true
                }
            },
            // 账号设置
            {
                path: 'userSet',
                component: _import('setting/userSet'),
                name: 'userSet',
                meta: {
                    title: '账号设置',
                    noCache: true
                }
            },
            // 系统设置
            {
                path: 'systemSet',
                component: _import('setting/systemSet'),
                name: 'systemSet',
                meta: {
                    title: '系统设置',
                    noCache: true
                }
            }
        ]
    },
    // 新增等级
    {
        path: '/setting',
        component: Layout,
        hidden: true,
        children: [{
            path: 'levelAdd',
            component: _import('setting/levelAdd'),
            name: 'levelAdd',
            meta: {
                title: '新增等级',
                icon: 'icon',
                noCache: true
            }
        }]
    },
    // 编辑等级
    {
        path: '/setting',
        component: Layout,
        hidden: true,
        children: [{
            path: 'levelEdit/:id',
            component: _import('setting/levelEdit'),
            name: 'levelEdit',
            meta: {
                title: '编辑等级',
                icon: 'icon',
                noCache: true
            }
        }]
    },
    // 新增优惠券
    {
        path: '/setting',
        component: Layout,
        hidden: true,
        children: [{
            path: 'addIntegral2',
            component: _import('setting/addIntegral2'),
            name: 'addIntegral2',
            meta: {
                title: '新增优惠券',
                icon: 'icon',
                noCache: true
            }
        }]
    },
    //编辑广告位
    {
        path: '/setting',
        component: Layout,
        hidden: true,
        children: [{
            path: 'editIntegral2/:id',
            component: _import('setting/editIntegral2'),
            name: 'editIntegral2',
            meta: {
                title: '编辑优惠券',
                icon: 'icon',
                noCache: true
            }
        }]
    },
    // 积分设置 - 新增/编辑优惠券
    {
        path: '/setting',
        component: Layout,
        hidden: true,
        children: [{
            path: 'editAddCoupon',
            component: _import('setting/editAddCoupon'),
            name: 'editAddCoupon',
            meta: {
                title: '编辑优惠券',
                icon: 'icon',
                noCache: true
            }
        }]
    },
    // 新增账号
    {
        path: '/setting',
        component: Layout,
        hidden: true,
        children: [{
            path: 'userAdd',
            component: _import('setting/userAdd'),
            name: 'userAdd',
            meta: {
                title: '新增账号',
                icon: 'icon',
                noCache: true
            }
        }]
    },
    // 编辑账号
    {
        path: '/setting',
        component: Layout,
        hidden: true,
        children: [{
            path: 'userEdit/:id',
            component: _import('setting/userEdit'),
            name: 'userEdit',
            meta: {
                title: '编辑账号',
                icon: 'icon',
                noCache: true
            }
        }]
    },
    // 没权限的页面
    {
        path: '/test',
        component: Layout,
        hidden: true,
        children: [{
            path: 'index',
            component: _import('test/index'),
            name: 'index',
            meta: {
                title: '暂无权限',
                icon: 'icon',
                noCache: true
            }
        }]
    },
    // 系统设置 - 新增优惠券
    {
        path: '/setting',
        component: Layout,
        hidden: true,
        children: [{
            path: 'systemAddCoupon',
            component: _import('setting/systemAddCoupon'),
            name: 'systemAddCoupon',
            meta: {
                title: '新增优惠券',
                icon: 'icon',
                noCache: true
            }
        }]
    },
    // 系统设置 - 编辑优惠券
    {
        path: '/setting',
        component: Layout,
        hidden: true,
        children: [{
            path: 'systemEditCoupon/:id',
            component: _import('setting/systemEditCoupon'),
            name: 'systemEditCoupon',
            meta: {
                title: '编辑优惠券',
                icon: 'icon',
                noCache: true
            }
        }]
    },
    /* --------------------消息中心----------------------- */
    //消息中心主页
    {
        path: '/message',
        component: Layout,
        redirect: 'noredirect',
        children: [{
            path: 'msgCenter',
            component: _import('message/msgCenter'),
            name: 'msgCenter',
            meta: {
                title: '消息中心',
                icon: 'message',
                noCache: true
            }
        }]
    },
    //群发消息
    {
        path: '/message',
        component: Layout,
        redirect: 'noredirect',
        hidden: true,
        children: [{
            path: 'groupSendMsg',
            component: _import('message/groupSendMsg'),
            name: 'groupSendMsg',
            meta: {
                title: '群发消息',
                icon: 'message',
                noCache: true
            }
        }]
    },
    // 错误页面 404 、 401
    {
        path: '/error',
        component: Layout,
        hidden: true,
        redirect: 'noredirect',
        name: 'errorPages',
        meta: {
            title: '错误页',
            icon: '404'
        },
        children: [
        {
            path: '401',
            component: _import('errorPage/401'),
            name: 'page401',
            meta: {
                title: '401错误页',
                noCache: true
            }
        },
        {
            path: '404',
            component: _import('errorPage/404'),
            name: 'page404',
            meta: {
                title: '404错误页',
                noCache: true
            }
        }]
    },
    {
        path: '*',
        redirect: '/404',
        hidden: true
    }
]